package com.itheima.advice;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class TimeAdvice {
    @Pointcut("execution(* com.itheima.dao.BookDao.save(..))")
    public void pt(){}
    @Around("pt()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        long beginTime = System.currentTimeMillis();
        for (int i = 0; i < 10000; i++) {
            Object proceed = pjp.proceed();
        }
        long endTime = System.currentTimeMillis();
        String name = pjp.getSignature().getName();
        String typeName = pjp.getSignature().getDeclaringTypeName();
        System.out.println("执行方法"+typeName+"."+name+"万次执行效率:"+(endTime-beginTime)+"ms");
        return null;
    }
}
